Skip to content

For each fun #9

Open
wants to merge 2 commits into
base: tf-upgrade
Choose a base branch
from

Conversation

morga471
Copy link

@morga471 morga471 commented Nov 1, 2024

@@ -183,7 +184,7 @@ resource "aws_iam_role" "role" {
}

resource "aws_iam_role_policy_attachment" "role" {
for_each = var.create ? toset(var.attached_policies) : toset([])
for_each = var.create ? local.attached_policies_map : toset([])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The false type of this has to match the true type. Change

: toset([])
: {}

region = data.aws_region.current.name
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"
account_alias = var.account_alias != "" && var.account_alias != null ? var.account_alias : "none"
attached_policies_map = { for idx, policy in var.attached_policies : idx => policy }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement will create in essence a count problem with sorting. Use it this way please:

attached_policies_map = { for p in var.attached_policies : p => p }

This is also the prior behavior. Otherwise, you'll end up with a lot of resources being deleted and recreated because you're changing the key.

Copy link
Contributor

@badra001 badra001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see changes

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants